package com.gs.weather.utils;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: Legolas
 * Date: 2017/10/30 0030
 */
public class DateUtils {

    public static Map<Object, Object> getYearMonthDay() {
        Calendar calendar = Calendar.getInstance();
        Map result = new HashMap();
        result.put("year", calendar.get(Calendar.YEAR));
        result.put("month", calendar.get(Calendar.MONTH) + 1 < 10 ? "0" + (calendar.get(Calendar.MONTH) + 1) : (calendar.get(Calendar.MONTH) + 1));
        result.put("day", calendar.get(Calendar.DAY_OF_MONTH) < 10 ? "0" + calendar.get(Calendar.DAY_OF_MONTH) : calendar.get(Calendar.DAY_OF_MONTH));
        return result;
    }

    public static String getYearToMinuteStr() {
        Calendar calendar = Calendar.getInstance();
        String content = "";
        content = content + calendar.get(Calendar.YEAR) +
                (calendar.get(Calendar.MONTH) + 1 < 10 ? "0" + (calendar.get(Calendar.MONTH) + 1) : (calendar.get(Calendar.MONTH) + 1)) +
                (calendar.get(Calendar.DAY_OF_MONTH) < 10 ? "0" + calendar.get(Calendar.DAY_OF_MONTH) : calendar.get(Calendar.DAY_OF_MONTH)) +
                (calendar.get(Calendar.MINUTE)<50?(calendar.get(Calendar.HOUR_OF_DAY) - 1<10?"0"+(calendar.get(Calendar.HOUR_OF_DAY) - 1):(calendar.get(Calendar.HOUR_OF_DAY) - 1)):calendar.get(Calendar.HOUR_OF_DAY)<10?"0"+calendar.get(Calendar.HOUR_OF_DAY):calendar.get(Calendar.HOUR_OF_DAY))+
                ((calendar.get(Calendar.MINUTE) + 10) % 60<10?("0"+(calendar.get(Calendar.MINUTE) + 10) % 60):(calendar.get(Calendar.MINUTE) + 10) % 60);
        //return content;
        return content.substring(0, content.length() - 1);
    }

    public static String getYearToMinuteStrPreHour() {
        Calendar calendar = Calendar.getInstance();
        String content = "";
        content = content + calendar.get(Calendar.YEAR) +
                (calendar.get(Calendar.MONTH) + 1 < 10 ? "0" + (calendar.get(Calendar.MONTH) + 1) : (calendar.get(Calendar.MONTH) + 1)) +
                (calendar.get(Calendar.DAY_OF_MONTH) < 10 ? "0" + calendar.get(Calendar.DAY_OF_MONTH) : calendar.get(Calendar.DAY_OF_MONTH)) +
                ((calendar.get(Calendar.HOUR_OF_DAY)-1)<10?"0"+(calendar.get(Calendar.HOUR_OF_DAY) - 1):(calendar.get(Calendar.HOUR_OF_DAY) - 1))+
                (calendar.get(Calendar.MINUTE)<10?("0"+calendar.get(Calendar.MINUTE)):calendar.get(Calendar.MINUTE));
        //return content;
         return "%"+content.substring(0, content.length() - 1)+"%";
    }

    //TODO
    public static String getYearToMinuteTest() {
        return "%20171105120%";
    }




    public static void main(String[] args) {
        System.out.println(getYearToMinuteStrPreHour());
    }

}
